package cn.doitedu.day08

import org.apache.spark.rdd.RDD
import org.apache.spark.sql.execution.SparkPlan
import org.apache.spark.sql.{Dataset, Encoder, SparkSession}
import org.apache.spark.sql.expressions.Window
import org.apache.spark.sql.types.StructType

object T02_DataSetDemo {

  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder().appName(this.getClass.getSimpleName)
      .master("local[4]")
      .getOrCreate()

    val lines: Dataset[String] = spark.read.textFile("data/words.txt")

    //1.Dataset持有着RDD
    val rdd: RDD[String] = lines.rdd

    //2.获取Dataset的schema
    val schema: StructType = lines.schema
    println(schema)
    //3.Dataset中有执行计划
    val plan: SparkPlan = lines.queryExecution.executedPlan
    println(plan)
    //4.Dataset中有Encoder
    val encoder: Encoder[String] = lines.encoder
    println(encoder)

  }
}
